interface UserType {
  userName: string;
  userInfo?: any;
  authorization?: string;
  userId?: number;
  tenantId: number;
}

const DefState: UserType = {
  userName: '访客',
  userInfo: undefined,
  authorization: undefined,
  userId: undefined,
  tenantId: 1,
};

export default {
  // 定义 model 的初始 state
  state: { ...DefState },

  // 定义改变该模型状态的纯函数
  reducers: {
    logout() {
      window.localStorage.removeItem('useinfos');
      window.localStorage.removeItem('authorinfo');

      return { ...DefState };
    },
    setUserInfo(prevState, payload) {
      const data = {
        userName: payload.userName,
        userInfo: payload,
        userId: payload.userId,
        authorization: payload.authorization,
        tenantId: 0,
      };

      window.localStorage.setItem('useinfos', JSON.stringify(data));
      window.localStorage.setItem('authorinfo', data.authorization);

      return data;
    },
  },
};
